﻿
using Grishko.SerilizeTools;
using AgencyEntityLib.BaseEntity;
using OutdoorLib.Context;
using Grishko.DataTier.SqlLibrary;
using OutdoorLib.BaseEntity.WS;
using OutdoorLib.BaseEntity.Agency;
using OutdoorLib.BaseEntity.Dictionary;
using System.ComponentModel;
using Grishko.DataTier;


namespace OutdoorLib.BaseEntity.Face
{
    [TagNameInfo(TagName = "Client")]
    public class Client : Face_U 
    {        

        [EntityNonSerialized]
        public string FullName 
        {
            get { return Name; }
        }

        [DefaultValue(0)]
        [SrchItemInfo(TxtPropertyName = "Рэйтинг")]        
        public int Rating{get;set;}

        [SrchItemInfo(TxtPropertyName = "Куратор")]        
        public Employeer Curator { get; set; }

        private TreeDictionaryItemValue _Ctegoria=null ;
        [SrchItemInfo(TxtPropertyName = "Категория", TreeDictionaryTypeID =TreeDictionaryItem .TreeDictionary_ClientsCategory ,PropControlType =SrchItemInfo.PropertyControlType.Tree)]        
        public TreeDictionaryItemValue Ctegoria
        {
            get { return _Ctegoria;}
            set {_Ctegoria =value ;}
        }
        
        private void SetContactValue(EnContactType ContactType, string ContactValue )
        {
            this.ContactList.RemoveItems(ContactType);
            this.ContactList.Add(new Contact { MainContact = true, ContactType = ContactType, ContactValue=ContactValue});            
        }

        private string GetContactValue (EnContactType  ContactType)
        {
            Contact c = ContactList.GetMainContact(ContactType);
            if (c==null) return string.Empty;
            return c.ContactValue;
        }
        
        
        [SrchItemInfo(TxtPropertyName = "Телефоны")]        
        public string Phones 
        { 
            get 
            {
                return GetContactValue(EnContactType.Phone );
                   
            } 
            set 
            {
                SetContactValue(EnContactType.Phone , value);
            }
        }

        [SrchItemInfo(TxtPropertyName = "Email")]        
        public string Email
        {
            get
            {
                return GetContactValue(EnContactType.Email );

            }
            set
            {
                SetContactValue(EnContactType.Email , value);
            }
        }

        [SrchItemInfo(TxtPropertyName = "Адрес")]        
        public string Adress
        {
            get
            {
                return GetContactValue(EnContactType.Address );

            }
            set
            {
                SetContactValue(EnContactType.Address , value);
            }
        }

        [SrchItemInfo(TxtPropertyName = "URL")]
        public string URL
        {
            get
            {
                return GetContactValue(EnContactType.URL );

            }
            set
            {
                SetContactValue(EnContactType.URL, value);
            }
        }


        private EntityList _ContactFaces = new EntityList();
        [SrchItemInfo(TxtPropertyName = "Контактные лица", ListType = typeof(ContactFace))]
        public virtual EntityList ContactFaces { get { return _ContactFaces ; } }

        public string CategoryAsString
        {
            get
            {
                if (null == Ctegoria)
                    return string.Empty;
                return Ctegoria.ToString();
            }

        }

            
        

    }
    }
 

